package com.qf.java2107.web.controller;

import com.qf.java2107.pojo.Passports;
import com.qf.java2107.service.PassengerService;
import com.qf.java2107.service.PassportsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author YB
 * @date 2022/01/07
 * @VERSION V1.0
 **/
@Controller
@RequestMapping("/passport")
public class PassportController {

    @Autowired
    private PassportsService passportsService;

    @GetMapping("/update")
    public ModelAndView updateui(Passports passports){
        ModelAndView mav = new ModelAndView("redirect:/passport/pagelist/1/10");
        mav.addObject("pass",passportsService.update(passports));
        return mav;
    }


    @GetMapping("/{id}")
    public ModelAndView update(@PathVariable("id")Integer id){
        ModelAndView mav = new ModelAndView("pass/edit");
        mav.addObject("pass",passportsService.findById(id));
        return mav;
    }

    @GetMapping("/delete/{id}")
    public String delete(@PathVariable("id")Integer id){
        passportsService.delete(id);
        return "forword:/pass/pagelist";
    }

    @GetMapping("/list")
    public ModelAndView findAll(){
        ModelAndView mav = new ModelAndView("pass/list");
        mav.addObject("pags",passportsService.findAll());
        return mav;
    }

    @GetMapping("/pagelist/{pageNum}/{pageSize}")
    public ModelAndView findPage(@PathVariable("pageNum")Integer pageNum,
                                 @PathVariable("pageSize")Integer pageSize){
        ModelAndView mav = new ModelAndView("pass/pagelist");
        mav.addObject("pageInfo",passportsService.findPage(pageNum,pageSize));
        return mav;
    }
}
